<template>
        <el-card shadow="never" style="max-height: 70vh; overflow: auto">
            <el-form ref="form" :model="form" :rules="rules" label-width="90px" :disabled="disabled">
                <el-form-item label="id:" prop="id" v-show="false">
                    <el-input v-model="form.id" disabled />
                </el-form-item>
                <el-form-item label="位置:" prop="place">
                    <el-select v-model="form.place" placeholder="请选择位置" clearable>
                        <el-option v-for="(item, index) in place" :key="index" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="标题:" prop="title">
                    <el-input v-model="form.title" placeholder="请输入标题" clearable />
                </el-form-item>
                <el-form-item label="图片:" prop="image">
                    <ImageUpload v-model="form.image" />
                </el-form-item>
                <el-form-item label="外链:" prop="link">
                    <InputLink v-model="form.link" placeholder="请输入值"></InputLink>
                </el-form-item>
                <el-form-item label="状态:" prop="status">
                    <el-select v-model="form.status" placeholder="请选择状态" clearable>
                        <el-option v-for="(item, index) in status" :key="index" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="排序:" prop="sortweight">
                    <el-input-number v-model="form.sortweight" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="创建者:" prop="create_by" v-if="false">
                    <el-input-number v-model="form.create_by" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="更新者:" prop="update_by" v-if="false">
                    <el-input-number v-model="form.update_by" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">确认 </el-button>
                    <el-button type="warning" @click="cancel">取消 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
</template>

<script>
import InputLink from "@/components/My/InputLink";
import { regionData } from 'element-china-area-data'
export default {
    name: 'EditForm',
    components: {InputLink},
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        editFormParams: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            // 编辑表单验证规则
            rules: {
                place: [{ required: true, message: "请选择位置", trigger: "blur" }],
                title: [{ required: true, message: "请输入标题", trigger: "blur" }],
                image: [{ required: true, message: "请上传图片", trigger: "blur" }],
                link: [{ required: true, message: "请输入链接地址", trigger: "blur" }],
                status: [{ required: true, message: "请选择状态", trigger: "blur" }],
            },
            form: {  },
            // 区域选择配置
            areaOptions: regionData,
            place:[
               { label: "首页", value: 'index' },
               { label: "培训首页", value: 'train_index' },
               { label: "科普详情", value: 'post_detail3' },
               { label: "医院首页", value: 'ch_index' },
            ],
            status:[
               { label: "正常", value: 1 },
               { label: "禁用", value: 2 },
            ],
        }
    },
    watch: {
        findFormData: {
           handler(nval) {
                if (JSON.stringify(nval) != '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                    })
                }
            },
            immediate: true,
            deep: false,
        },
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },

        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', this.form)
                }
            })
        },

        // 表单重置
        reset() {
            this.resetForm('form')
        }
    }
}
</script>
